<!doctype html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- 必须的 meta 标签 -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap 的 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../../static/css/main.css" th:href="@{/static/css/main.css}">
    <title>图书信息管理</title>
</head>
<body>
<div class="row-2">
    <nav class="navbar navbar-expand-lg navbar-light bg-light" style="height: 80px">
        <a th:href="@{/admin/user}" class="topA navbar-brand">用户管理</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02"
                aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
            <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
                <li class="nav-item active">
                    <a class="topA nav-link" th:href="@{/book/book}" href="#">图书信息管理</a>
                </li>
                <li class="nav-item">
                    <a class="topA nav-link" th:href="@{/order/selectAllOrder}" href="#">订单管理</a>
                </li>
            </ul>
            <span th:text="${message}" style="margin-right: 450px;color: red"></span>
            <span class="form-inline my-2 my-lg-0">
                <button id="add" type="button" class="btn btn-primary">增加</button>
                <input id="search" name="bookName" class="form-control mr-sm-2" type="text" placeholder="Search">
                <button class="btn btn-outline-success my-2 my-sm-0" th:onclick="bookList(1)" type="submit">查询</button>
            </span>
        </div>
    </nav>
</div>

<div class="row-10">
    <div id="tab">
        <table class="table">
            <thead>
            <tr>
                <th scope="col">序号</th>
                <th scope="col">书名</th>
                <th scope="col">作者</th>
                <th scope="col">图书总数量</th>
                <th scope="col">卖出数量</th>
                <th scope="col">评分</th>
                <th scope="col">价格</th>
                <th scope="col">操作</th>
            </tr>
            </thead>
            <tbody id="tbody">
            <tr th:each="book:${books}">
                <th th:text="${book.id}" scope="row" >1</th>
                <td th:text="${book.bookName}" >《平凡世界》</td>
                <td th:text="${book.author}" >作者</td>
                <td th:text="${book.allCount}">200</td>
                <td th:text="${book.sellCount}">10</td>
                <td th:text="${book.mark}">9.7</td>
                <td th:text="${book.price}">33</td>
                <td>
                    <!--模态窗口-->
                    <div id="myMo" class="modal" tabindex="-1">
                        <div class="container">
                            <div class="modal-content">
                                <div class="modal-body">
                                    用户名：<input type="text" id="username" name="username"><br>
                                    密码：<input type="password" id="password" name="password"><br>
                                    用户身份：<input type="text" id="identity" name="identity"><br>
                                    用户金钱：<input type="text" id="money" name="money"><br>
                                    <button type="submit">提交</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="row">
        <div class="offset-5">
            <nav aria-label="Page navigation example">
                <ul class="pagination">
                    <li class="page-item">
                        <a class="page-link" th:href="@{javascript:bookList({b})(b=${info.prePage})}"
                           aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </li>
                    <li th:each="inf:${#numbers.sequence(1,info.pages,+1)}"  class="page-item">
                        <a th:href="@{javascript:bookList({b})(b=${inf})}" th:text="${inf}" class="page-link" >1</a>
                    </li>
                    <li class="page-item">
                        <a class="page-link" th:href="@{javascript:bookList({b})(b=${info.nextPage})}"
                           aria-label="Next">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </li>
                </ul>
            </nav>
        </div>
    </div>
</div>
<!--模态窗口-->
<div id="myModal" class="modal" tabindex="-1">
    <div class="container">
        <div class="modal-content">
            <div class="modal-body">
                <form th:action="@{/book/insert}">
                    书名：<input type="text" name="bookName"><br><br>
                    作者：<input type="text" name="author"><br><br>
                    内容：<input type="text" name="content"><br><br>
                    总数量：<input type="text" name="allCount"><br><br>
                    评分：<input type="text" name="mark"><br><br>
                    价格：<input type="text" name="price"><br><br>
                    <select  name="typeName">
                        <th:block th:each="type:${types}">
                        <option th:text="${type.typeName}" th:value="${type.typeName}">1</option>
                        </th:block>
                    </select>
                    <br>
                    <br>
                    <button type="submit">提交</button>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- JavaScript 文件是可选的。从以下两种建议中选择一个即可！ -->

<!-- 选项 1：jQuery 和 Bootstrap 集成包（集成了 Popper） -->

<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>

<script>
    <!-- 图书列表分页-->
    function bookList(pageNum) {
        var bookName = $("#search").val();
        $.ajax({
            url: '/bookCity/book/bookPage',
            data: {
                pageNum: pageNum,
                bookName: bookName
            },
            dataType: 'json',
            success: function (data) {
                console.log(data);
                let first = `<table class="table">
        <thead>
        <tr>
            <th scope="col">序号</th>
                <th scope="col">书名</th>
                <th scope="col">作者</th>
                <th scope="col">图书总数量</th>
                <th scope="col">卖出数量</th>
                <th scope="col">评分</th>
                <th scope="col">价格</th>
                <th scope="col">操作</th>
        </tr>
        </thead>`;
                var str = '';
                let last = '</table>';
                $.each(data.list, function (index, item) {
                    str += `<tbody id="tbody">
            <tr>
                <th  scope="row" >${item.id}</th>
                <td  >${item.bookName}</td>
                <td  >${item.author}</td>
                <td >${item.allCount}</td>
                <td >${item.sellCount}</td>
                <td >${item.mark}</td>
                <td >${item.price}</td>
                <td>
                    <!--模态窗口-->
                    <div id="myMo" class="modal" tabindex="-1">
                        <div class="container">
                            <div class="modal-content">
                                <div class="modal-body">
                                    用户名：<input type="text" id="username" name="username"><br>
                                    密码：<input type="password" id="password" name="password"><br>
                                    用户身份：<input type="text" id="identity" name="identity"><br>
                                    用户金钱：<input type="text" id="money" name="money"><br>
                                    <button type="submit">提交</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
            </tbody>`
                })
                $(".table").html(first + str + last);
            }
        })
    }

    //模态窗口
    $('#add').click(function () {
        $('#myModal').modal('show')
        ;
    });

</script>


</body>
</html>
















